Skip to content

[Engineering] fix: profiler result page never clamped below 1 - #3405

Merged
xen2 merged 2 commits into
stride3d:masterfrom
Nicogo1705:profiler-page-clamp
Sep 13, 2026
Merged

xen2 merged 2 commits into
stride3d:masterfrom
Nicogo1705:profiler-page-clamp

Conversation

@Nicogo1705

Copy link
Copy Markdown
Contributor

PR Details

Split out of #3388 as requested in review.

GameProfilingSystem clamps CurrentResultPage against the page count. On the first frames after profiling is enabled there are no results yet, so the page count is 0 and the page is clamped to 0, where it stays: once results arrive the profiler shows "PAGE 0 OF N" over an empty list. The clamp now never goes below page 1.

Verified with the in-game profiler (F2 / P in the VoxelGI demo): the first page shows its results right after enabling.

Related Issue

None filed; small enough to be its own fix.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

⚠️ Written with AI assistance (Claude Code), driven and verified by me; needs a real review. 🤖 Generated with Claude Code

On the first frames after profiling is enabled there are no results
yet, so numberOfPages is 0 - and CurrentResultPage, clamped with
Math.Min against it, dropped to 0 and stayed there. The profiler then
showed page 0 of N over an empty list once results arrived.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit dd27c24)
var elementsPerPage = (int)Math.Floor(availableDisplayHeight / TextRowHeight);
numberOfPages = (uint)Math.Ceiling(profilingResults.Count / (float)elementsPerPage);
CurrentResultPage = Math.Min(CurrentResultPage, numberOfPages);
CurrentResultPage = Math.Max(1, Math.Min(CurrentResultPage, numberOfPages));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use this.
Or, even better this, which is the Microsoft's recommended way now.

int.Clamp(value, 1, numberOfPages)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: uint.Clamp(CurrentResultPage, 1, Math.Max(1, numberOfPages)). The upper bound is kept at 1 or more because numberOfPages is 0 until the first results arrive, and Clamp throws when max < min.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@xen2
xen2 merged commit 73b8d0c into stride3d:master Sep 13, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants